/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.letmeshare.stockkeeper.component;

import java.util.List;
import javax.swing.table.DefaultTableModel;
import org.letmeshare.stockkeeper.purchase.entities.Purchase;
import org.letmeshare.stockkeeper.purchase.entities.PurchaseEntry;
import org.letmeshare.stockkeeper.sale.entities.Bill;
import org.letmeshare.stockkeeper.sale.entities.BillEntry;

/**
 *
 * @author Aby
 */
public class PurchaseEntryTableModel extends DefaultTableModel{

private String[] cols=new String []  {
                "Sr.No", "Item Name", "Rate", "Quantity","Price"
            };

    public PurchaseEntryTableModel(Purchase purchase) {
        if(purchase==null){
          setEmpty();
        }else{
            popupModel(purchase.getEntries());
        }
    }

    public PurchaseEntryTableModel(List<PurchaseEntry> entrys) {
        popupModel(entrys);
    }
    
    private void popupModel(List<PurchaseEntry> purchaseEntries){
        if(purchaseEntries==null || purchaseEntries.size()<1){
            setEmpty();
            return;
        }else{
            Object[][] data=new Object[purchaseEntries.size()+1][5];
            for(int i=0;i<purchaseEntries.size();i++){
                data[i]=new Object[]{i+1,purchaseEntries.get(i).getItem().getName(),purchaseEntries.get(i).getItem().getUnitPrice(),purchaseEntries.get(i).getQty(),purchaseEntries.get(i).getAmount()};
            }
            setDataVector(data, cols);
        }
    }

    private void setEmpty() {
         setDataVector( null,
            cols);
    }
     @Override
    public boolean  isCellEditable(int row,int col){
        return false;
    }
    
}
